package Game;

/**
 * 游戏类
 */

public class Game {

    /**
     * 判断方法
     * @param player 分数
     * @param cpu 分数
     * @return 1玩家胜、0平局、-1电脑胜
     */
    static int compare(int player, int cpu) {
        int ret = cpu - player;
        if (ret == 2) {
            ret = -1;
        }
        if (ret == -2) {
            ret = 1;
        }
        return ret;
    }

    public void run() {
        String[] arr = {"石头","剪刀","布"};
        Player player = new Player();
        Computer cpu = new Computer();

        for (int i = 0; i < 10; i++) {
            System.out.println("第" + (i + 1) + "局");
            cpu.punch();//电脑出拳
            player.punch();//玩家出拳

            int pyNum = player.getNumber();
            int cpuNum = cpu.getNumber();
            int pyScore = player.getScore();
            int cpuScore = cpu.getScore();
            if (compare(pyNum, cpuNum) > 0) {
                System.out.println("玩家+1分");
                player.setScore(++pyScore);
            } else if (compare(pyNum, cpuNum) < 0) {
                System.out.println("电脑+1分");
                cpu.setScore(++cpuScore);
            }else {
                System.out.println("均不得分");
            }
            System.out.println("电脑："+arr[cpuNum]+" | 玩家："+arr[pyNum]);
            System.out.println("电脑分数：" + cpuScore + "  玩家分数：" + pyScore);
        }
        if (cpu.getScore() > player.getScore()) {
            System.out.println("电脑赢");
        } else if (cpu.getScore() < player.getScore()) {
            System.out.println("玩家赢");
        } else {
            System.out.println("平局");
        }
    }

    public static void main(String[] args) {
        Game game = new Game();
        game.run();

    }
}
